﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SaaS.Core.Authorization;
using Web.System.Services.Gateways;
using SaaS.Model.Dto.Gateways;
using XCore.Authorization;
using XCore.Domain.Dto;
using XCore.Domain.Dto.Page;
using XCore.Web;
using SaaS.Model.Entity.Gateways;

namespace Web.System.Controllers.Gateways
{
    [Route("api/gateway/[controller]/[action]")]
    [ApiController]
    public class NoticeController : SystemControllerBase
    {
        private readonly NoticeAppService _noticeApplicationService;
        public NoticeController(NoticeAppService noticeApplicationService)
        {
            _noticeApplicationService = noticeApplicationService;
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Permission(PermissionNames.Gateway_Notice)]
        public ActionResult List(PagedInput input)
        {
            return PageResult(SDC.Notices.OrderByDescending(c => c.CreationTime), c => new
            {
                c.Id,
                c.CreationTime,
                c.IP,
                c.Flow,
                c.Importance,
                c.NoticeSetting.Images,
                c.ReleaseTime,
                c.Status,
                c.Summary,
                c.Title,
                c.Type
            });
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        //[HttpPost]
        //[Authorization(PermissionNames.Gateway_Notice_Create)]
        //public ActionResult Save(NoticeInput input)
        //{
        //    _noticeApplicationService.CreateOrEdit<Notice, NoticeInput>(input);
        //    return Ok(input.Id.HasValue ? ResultFormat.EditSuccess : ResultFormat.CreateSuccess);
        //}
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //[HttpDelete]
        //[Authorization(PermissionNames.Gateway_Notice_Delete)]
        //public ActionResult Delete(int id)
        //{
        //    return Ok(_noticeApplicationService.Delete<Notice>(id));
        //}
        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Permission(PermissionNames.Gateway_Notice_Query)]
        public ActionResult Info(int id)
        {
            return Ok(SDC.Notices.Where(c => c.Id == id).Select(c => new
            {
                c.Id,
                c.Importance,
                c.ReleaseTime,
                c.Status,
                c.Summary,
                c.Title,
                c.Type,
                c.Flow
            }));
        }
    }
}